package com.gzyz.cheetah.controller;


import com.gzyz.cheetah.entity.dto.ListIdDTO;
import com.gzyz.cheetah.entity.dto.PageDTO;
import com.gzyz.cheetah.entity.table.SensitiveWord;
import com.gzyz.cheetah.service.ISensitiveWordService;
import com.gzyz.cheetah.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 违禁词表 前端控制器
 * </p>
 *
 * @author xclhove
 * @since 2023-11-06
 */
@RestController
@RequestMapping("/sensitive-word")
public class SensitiveWordController {

    @Autowired
    ISensitiveWordService iSensitiveWordService;
    @GetMapping("/addSensitiveWord")
    public Result<Object> addSensitiveWord(@RequestParam String sensitiveWord) {
        iSensitiveWordService.addSensitiveWord(sensitiveWord);
        return Result.success();
    }

    @PostMapping("/delete/{id}")
    public Result <Object> deleteSensitiveWordById(@PathVariable Integer id) {
        iSensitiveWordService.deleteSensitiveWordById(id);
        return Result.success();
    }

    @PostMapping("/deleteByIds")
    public Result <Object> deleteSensitiveWordsByIds(@RequestBody ListIdDTO listIdsDTO) {
        iSensitiveWordService.deleteSensitiveWordsByIds(listIdsDTO.getIds());
        return Result.success();
    }


    @PostMapping("/update")
    public Result <Object> updateSensitiveWordById(@RequestBody SensitiveWord sensitiveWord) {
        iSensitiveWordService.updateSensitiveWordById(sensitiveWord);
        return Result.success();
    }


    @PostMapping("/getSensitiveById/{sensitiveId}")
    public Result <Object> getSensitiveById(@PathVariable Integer sensitiveId) {
        SensitiveWord word = iSensitiveWordService.getSensitiveById(sensitiveId);
        return Result.success(word);
    }

    @GetMapping("/searchAndPageList")
    public Result <PageDTO<SensitiveWord>> searchAndPageList(@RequestParam(required = false) String searchText, @RequestParam Integer pageNumber, @RequestParam Integer pageSize) {
        PageDTO<SensitiveWord> pagelist = iSensitiveWordService.searchAndPageList(searchText,pageNumber,pageSize);
        return Result.success(pagelist);
    }
}
